package com.suning.sawp.service.impl.mainpush;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.suning.nsfuaa.employee.dto.EmployeeInfo;
import com.suning.sawp.dto.mainpush.StoreManDto;
import com.suning.sawp.intf.dao.LastestChooseManDaoService;
import com.suning.sawp.intf.mainpush.LastestChooseManService;
import com.suning.sawp.po.mainpush.LastestChooseMan;

@Service("lastestChooseManService")
public class LastestChooseManServiceImpl implements LastestChooseManService {

    private static final int LIMIT = 50;
    
    @Resource
    LastestChooseManDaoService lastestChooseManDaoService;
    
    @Override
    public void saveLastestChooseMans(String storeCode, String categoryCode, List<StoreManDto> storeMans) {
        // 保存客户端提交过来的最近选择人列表
        lastestChooseManDaoService.saveLastestChooseMan(storeCode, categoryCode, storeMans);
        // 删除超出上限的选择人
        lastestChooseManDaoService.removeAboveChooseMan(storeCode, categoryCode, LIMIT);
    }

    @Override
    public List<EmployeeInfo> getLastestChooseMans(String storeCode, String categoryCode) {
        List<EmployeeInfo> employeeInfos = new ArrayList<EmployeeInfo>();
        List<LastestChooseMan> list = lastestChooseManDaoService.queryLastestChooseMans(storeCode, categoryCode);
        for (LastestChooseMan chooseMan : list) {
            EmployeeInfo employeeInfo = new EmployeeInfo();
            employeeInfo.setEmployeeId(chooseMan.getStaffId());
            employeeInfo.setEmployeeName(chooseMan.getStaffName());
            employeeInfos.add(employeeInfo);
        }
        return employeeInfos;
    }

}